import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { isNumber } from "@pureadmin/utils";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  name: [{ required: true, message: "模拟卷名称为必填项", trigger: "blur" }],
  type: [{ required: true, message: "模拟卷类型为必填项", trigger: "blur" }],
  times: [{ required: true, message: "模拟考试时长为必填项", trigger: "blur" }],
  totalscore: [
    {
      validator: (rule, value, callback) => {
        if (value === "") {
          callback();
        } else if (!isNumber(value)) {
          callback(new Error("请输入正确的总分值"));
        } else if (value == 0) {
          callback(new Error("总分值不能为0"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ]
});

export const formScoreRules = reactive(<FormRules>{});
